<template>
    <div class="container">
        <div class='u-title f-mtp10'>
            <h2>知识列表</h2>
            <span class='u-title-btn'>添加</span>
        </div>
        <el-table
            :data="tableData"
            border
            style="width: 100%">
            <el-table-column prop="name" label="分类名称" width="120"></el-table-column>
            <el-table-column prop="remarks" label="备注" width="180"></el-table-column>
            <el-table-column prop="manage" label="操作">
                <template slot-scope="scope">
                    <span @click="handleEdit(scope.$index, scope.row)" class='s-c-green f-csp f-mrt10'>编辑</span>
                    <span class='s-c-red f-csp'>删除</span>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'AddKnowledgeClassify',
  data() {
    return {
      content: '<p>example content</p>',
      editorOption: { /* quill options */ },
      departmentId: '',  
      departmentList: [],  // 部门列表  
      phone: '',
      password: '',
      rePassword: '',
      name: '',  
      tableData: [
        {
          name: '热门推荐',
          remarks: '330326199908080606',
        }, {
          name: '一周热文',
          remarks: '上海市普陀区金沙江路 1517 弄'
        }, {
          name: '法律百科',
          remarks: '上海市普陀区金沙江路 1519 弄'
        }, {
          name: '法律文书',
          remarks: '上海市普陀区金沙江路 1516 弄'
        }
      ]
    }
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill
    }
  },
  mounted() {
    console.log('this is current quill instance object', this.editor)
  },
  created: function() {
    this.getDepartmentList();
  },
  methods: {
    onEditorBlur(quill) {
      console.log('editor blur!', quill)
    },
    onEditorFocus(quill) {
      console.log('editor focus!', quill)
    },
    onEditorReady(quill) {
      console.log('editor ready!', quill)
    },
    onEditorChange({ quill, html, text }) {
      console.log('editor change!', quill, html, text)
      this.content = html
    },  
    // 
    submit() {
      this.createStaff();  
    },  
    // 添加员工 
    createStaff() {
      console.log('createStaff-------------', this.name);  
      const _this = this;
      const params = new URLSearchParams();
      params.append('phone', this.phone);
      params.append('name', this.name);
      params.append('departmentId', this.departmentId);
      params.append('password', this.password);
      params.append('rePassword', this.rePassword);
      axios.post(`${this.GLOBAL.baseUrl}/api/admin/createStaff`, params, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
      })
      .then((res) => {
        console.log(res);
        if (res.data.returnCode === 200) {
        
          _this.$message({
            message: '恭喜你，修改成功！',
            type: 'success'
          });
          this.$router.push('/home/organizationalStructure');
        //   _this.getList();
        } else {
          _this.$message({
            message: res.data.message,
            type: 'warning'
          });
        }
      })
      .catch((error) => {
        console.log(error);
      });  
    }, 
    // 获取部门列表  
    getDepartmentList() {
      const _this = this;
      axios.get(`${this.GLOBAL.baseUrl}/api/admin/getDepartmentList`).then(res => {
        if(res.data.returnCode == 200) {
          console.log('list:::', res.data.data);
          _this.departmentList = res.data.data;
        }
      }).catch(err => {
        console.error('err::', err);
      })  
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.upload-tip{
    font-size: 12px;
    color: #999;
    margin-top: 10px;
    line-height: 24px;
}

.container{
  width: 800px;
  /* margin: 0 auto; */
}
.mn{
    padding: 30px 0 50px 0;
}
.item{
    display: flex;
    margin-bottom: 10px;
}
.item>label{
    display: inline-block;
    width: 90px;
    line-height: 40px;
    text-align: right;
    margin-right: 10px;
}
.item>label::before{
    content: '*';
    line-height: 40px;
    color: red;
    margin-right: 5px;
}
.item-right{
    width: 600px
}
.btn-box{
    padding-left: 90px;
}
</style>
